<?php
header("Content-Type: text/html; charset=UTF-8");

// 含入系統（資料庫）設定檔
require('config.inc.php');
require('db.php');
// 連結資料庫伺服器
db_connect();

// 選擇資料庫
db_select();

$user = $_POST['user'];
$pass = $_POST['pass'];
$name = $_POST['name'];
$email = $_POST['email'];
//$sex = $_POST['sex'];
/*
$sql = '';
$sql .= 'SELECT * FROM Authentication WHERE ID=\'' . $user . '\'';
$result = mysql_query($sql);
*/
//if (!$result) {
//    die('Invalid query: ' . mysql_error());
//}

if($_POST['sex'] =="M"){
	$sex = "男";
} else {
	$sex = "女";
}
/*
$row_num = mysql_num_rows($result);
echo "$row_num rows<br>";
*/
/*
if ($row_num>0) {
		<script language="JavaScript">
				window.alert("此帳號已重複!請重新申請!");
		</script>
	//header('Location: http://trackary.com/beta/goo/user/user.html');
} else {*/
	echo "此帳號可申請<br>";
	echo "$name 帳號新增成功<br>";
	echo "帳號資料如下：<br>";
	echo "帳號：$user<br>";
	echo "密碼：$pass<br>";
	echo "E-mail：$email<br>";
	echo "性別：$sex<br>";
	// 新增帳號
	// 建構 SQL 指令）
	$sql = '';
	$sql .= 'insert into Authentication (ID,Password, Name, Email, Sex) values ';
	$sql .= '(\'' . $user . '\',\'' . $pass . '\',\'' . $name . '\',\'' . $email . '\',\'' . $_POST['sex'] . '\');';
	// 執行 SQL 指令
	$result = mysql_query($sql) or die('Invalid query: ' . mysql_error());
//}
//echo $sex;

// 資料庫連結斷線
db_close();
?>
